package com.hdsx.restful.glzt.roadline.cdsl.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.ao.util.GemotryUtil;
import com.hdsx.restful.glzt.roadline.cdsl.bean.Cdsl;
import com.hdsx.restful.glzt.roadline.cdsl.mapper.CdslMapper;
import com.hdsx.restful.glzt.roadline.cdsl.service.CdslService;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Line;
import com.hdsx.restful.glzt.roadline.lxxx.bean.LxAreaDetail;
import com.hdsx.restful.util.CheckEmpty;

@Service
public class CdslServiceImpl extends BaseOpearte<Cdsl> implements CdslService{
public CdslServiceImpl() {
		super("GIS_CDSL");
	}

	@Resource(name="cdslMapper")
	private CdslMapper mapper;

	@Override
	public int queryCountByParameter(String lxdm) {
		Map<String,String> map=new HashMap<String, String>();
		map.put("lxdm",lxdm);
		return mapper.queryCountByParameter(map);
	}
	
	@Override
	public List<Cdsl> queryByParameter(String lxdm, int begin, int end) {
		
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("begin",begin);
		parameter.put("end", end);
		parameter.put("lxdm",lxdm);
		List<Cdsl> lists=mapper.queryByParameter(parameter);
		for(Cdsl cdsl:lists){
			cdsl.setShape(selectShape("ID= '"+cdsl.getId()+"'"));
		}
		return lists;
	}

	@Override
	public String queryCdslString(String id) {
		IGeometry shape=selectShape("ID= '"+id+"'");
		return GemotryUtil.generateLineString(shape);
	}
	
	@Override
	public List<Cdsl> queryDetail(Map<String,Object> map){
		return mapper.queryDetail(map);
	}
	
	@Override
	public int countDetail(Map<String,Object> map){
		return mapper.countDetail(map);
	}
	
	@Override
	public Cdsl queryById(String id) {
		return mapper.selectById(id);
	}

	@Override
	public Line ldDetail(Line param) {
		Line line = new Line();
		if(!CheckEmpty.isEmptyString(param.getId())){
			Cdsl cdsl = mapper.selectById(param.getId());
			try {
				PropertyUtils.copyProperties(line, cdsl);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				line = null;
			}
		}else if(!CheckEmpty.isEmptyString(param.getLxdm())){
			Line detail = mapper.ldDetail(param);
			line.setLxdm(param.getLxdm());
			line.setQdzh(param.getQdzh());
			line.setZdzh(param.getZdzh());
			line.setXzqhbm(param.getXzqhbm());
			line.setSxxfx(param.getSxxfx());
			line.setLxmc(detail.getLxmc());
			line.setQdmc(detail.getQdmc());
			line.setZdmc(detail.getZdmc());
			line.setLc(detail.getLc());
		}
		return line;
	}
	
	@Override
	public List<LxAreaDetail> lxArea(Line param){
		return mapper.lxArea(param);
	}
}
